<template>
  <div class="menu-container">
    <el-card class="menu-card">
      <template #header>
        <div class="card-header">
          <span>菜单管理</span>
          <el-button type="primary" @click="handleAddMenu">添加菜单</el-button>
        </div>
      </template>
      
      <el-table
        :data="menus"
        row-key="id"
        :tree-props="{ children: 'children' }"
        style="width: 100%"
      >
        <el-table-column prop="name" label="菜单名称" />
        <el-table-column prop="path" label="路由路径" />
        <el-table-column prop="component" label="组件路径" />
        <el-table-column prop="sort" label="排序" width="80" />
        <el-table-column label="操作" width="200">
          <template #default="scope">
            <el-button size="small" @click="handleEdit(scope.row)">编辑</el-button>
            <el-button 
              size="small" 
              type="danger" 
              @click="handleDelete(scope.row)"
            >删除</el-button>
          </template>
        </el-table-column>
      </el-table>
    </el-card>
  </div>
</template>

<script setup>
import { ref } from 'vue'
import { ElMessageBox, ElMessage } from 'element-plus'

const menus = ref([
  {
    id: 1,
    name: '系统管理',
    path: '/system',
    component: 'Layout',
    sort: 1,
    children: [
      {
        id: 2,
        name: '用户管理',
        path: 'user',
        component: 'system/user/index',
        sort: 1
      },
      {
        id: 3,
        name: '角色管理',
        path: 'role',
        component: 'system/role/index',
        sort: 2
      }
    ]
  }
])

const handleAddMenu = () => {
  ElMessage.success('添加菜单功能待实现')
}

const handleEdit = (menu) => {
  ElMessage.success(`编辑菜单 ${menu.name} 功能待实现`)
}

const handleDelete = (menu) => {
  ElMessageBox.confirm(`确定要删除菜单 ${menu.name} 吗？`, '提示', {
    confirmButtonText: '确定',
    cancelButtonText: '取消',
    type: 'warning'
  }).then(() => {
    ElMessage.success(`菜单 ${menu.name} 已删除`)
  }).catch(() => {
    ElMessage.info('已取消删除')
  })
}
</script>

<style scoped lang="scss">
.menu-container {
  padding: 20px;
}

.menu-card {
  .card-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
  }
}
</style> 